home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 July / Macworld (1999-07).dmg / Serious Software / OpenWorld demo 2.0 / Development / Utils / OpenWorld_utils.c next >
Text File  |  1999-04-21  |  2KB  |  77 lines

  1. /*
  2. OpenWorld_utils.h
  3.  
  4. Useful routines for OpenWorld (source file)
  5.  
  6. Version 1.0
  7. Copyright ©1998-99, Marco Bambini, Inc. All rights reserved.
  8. */
  9.  
  10. #include "OpenWorld_utils.h"
  11.  
  12.  
  13. //*********************************************************************************************************//
  14. // up_strstr
  15. // search fpr the string pat in the string str ignoring case
  16. //
  17. // modified by Marco Bambini
  18. // based on Metrowerks Standard Library Version 4.0  1998 August 10 (Copyright © 1995-1998 Metrowerks, Inc.)
  19. //
  20. // returns NULL if pat is not found
  21. //
  22. // PowerPC only version
  23. //*********************************************************************************************************//
  24. char *up_strstr(const char * str, const char * pat)
  25. {
  26. #ifdef __POWERPC__
  27.  
  28.     unsigned char * s1 = (unsigned char *) str-1;
  29.     unsigned char * p1 = (unsigned char *) pat-1;
  30.     unsigned long firstc, c1, c2;
  31.     
  32.     if ((pat == NULL) || (!(firstc = toupper(*++p1))))    /* 980807  vss  PPC must be pre-increment */
  33.                                         /* 980424  mm   if pat is a NULL pointer, we return str */
  34.                                         /* 971017  beb  if pat is an empty string we return str */
  35.         return((char *) str);
  36.  
  37.     while(c1 = toupper(*++s1))
  38.         if (c1 == toupper(firstc))
  39.         {
  40.             const unsigned char * s2 = s1-1;
  41.             const unsigned char * p2 = p1-1;
  42.             
  43.             while ((c1 = toupper(*++s2)) == (c2 = toupper(*++p2)) && c1);
  44.             
  45.             if (!c2)
  46.                 return((char *) s1);
  47.         }
  48. #endif
  49.     return(NULL);
  50. }
  51.  
  52. //*********************************************************************************************************//
  53. // up_strcmp
  54. // compare two strings ignoring case
  55. //
  56. // modified by Marco Bambini
  57. // based on Metrowerks Standard Library Version 4.0  1998 August 10 (Copyright © 1995-1998 Metrowerks, Inc.)
  58. //
  59. // returns 0 if equal
  60. //
  61. // PowerPC only version
  62. //*********************************************************************************************************//
  63. int up_strcmp(const char * str1, const char * str2)
  64. {
  65. #ifdef __POWERPC__
  66.  
  67.     const    unsigned char * p1 = (unsigned char *) str1 - 1;
  68.     const    unsigned char * p2 = (unsigned char *) str2 - 1;
  69.                 unsigned long        c1, c2;
  70.         
  71.     while ((c1 = toupper(*++p1)) == (c2 = toupper(*++p2)))
  72.         if (!c1)
  73.             return(0);
  74.     
  75.     return(c1 - c2);
  76. #endif
  77. }